export default {

	//    productList:[],

	//    setProductList(data){ 
	//        this.productList = data
	//    },
	utf8ByteToUnicodeStr(utf8Bytes) {
		var unicodeStr = "";
		for (var pos = 0; pos < utf8Bytes.length;) {
			var flag = utf8Bytes[pos];
			var unicode = 0;
			if ((flag >>> 7) === 0) {
				unicodeStr += String.fromCharCode(utf8Bytes[pos]);
				pos += 1;

			} else if ((flag & 0xFC) === 0xFC) {
				unicode = (utf8Bytes[pos] & 0x3) << 30;
				unicode |= (utf8Bytes[pos + 1] & 0x3F) << 24;
				unicode |= (utf8Bytes[pos + 2] & 0x3F) << 18;
				unicode |= (utf8Bytes[pos + 3] & 0x3F) << 12;
				unicode |= (utf8Bytes[pos + 4] & 0x3F) << 6;
				unicode |= (utf8Bytes[pos + 5] & 0x3F);
				unicodeStr += String.fromCodePoint(unicode);
				pos += 6;

			} else if ((flag & 0xF8) === 0xF8) {
				unicode = (utf8Bytes[pos] & 0x7) << 24;
				unicode |= (utf8Bytes[pos + 1] & 0x3F) << 18;
				unicode |= (utf8Bytes[pos + 2] & 0x3F) << 12;
				unicode |= (utf8Bytes[pos + 3] & 0x3F) << 6;
				unicode |= (utf8Bytes[pos + 4] & 0x3F);
				unicodeStr += String.fromCodePoint(unicode);
				pos += 5;

			} else if ((flag & 0xF0) === 0xF0) {
				unicode = (utf8Bytes[pos] & 0xF) << 18;
				unicode |= (utf8Bytes[pos + 1] & 0x3F) << 12;
				unicode |= (utf8Bytes[pos + 2] & 0x3F) << 6;
				unicode |= (utf8Bytes[pos + 3] & 0x3F);
				unicodeStr += String.fromCodePoint(unicode);
				pos += 4;

			} else if ((flag & 0xE0) === 0xE0) {
				unicode = (utf8Bytes[pos] & 0x1F) << 12;;
				unicode |= (utf8Bytes[pos + 1] & 0x3F) << 6;
				unicode |= (utf8Bytes[pos + 2] & 0x3F);
				unicodeStr += String.fromCharCode(unicode);
				pos += 3;

			} else if ((flag & 0xC0) === 0xC0) { //110
				unicode = (utf8Bytes[pos] & 0x3F) << 6;
				unicode |= (utf8Bytes[pos + 1] & 0x3F);
				unicodeStr += String.fromCharCode(unicode);
				pos += 2;

			} else {
				unicodeStr += String.fromCharCode(utf8Bytes[pos]);
				pos += 1;
			}
		}
		return unicodeStr;
	},

	//判断三码 结果中P为物料编码，Q为数量，C为箱号，K为库位，T为托码，O为其他情况，Z天津组长工号，S昆山组长工号
	scanCode(codeStr) {
		var numReg = /^[0-9]*$/;
		var numRe = new RegExp(numReg)
		var result = [];
		
		if (codeStr == "R" || codeStr == "CH") {
			result[0] = "K";
			result[1] = boxCode;
		} else if (codeStr.includes("-")) {
			var arr = [];
			arr = codeStr.split("-");
			if (arr.length >= 3) {
				var boxCode = arr[arr.length - 2] + arr[arr.length - 1];
				result[0] = "C";
				result[1] = boxCode;
			} else if (arr.length > 0 && arr.length < 3) {
				var char = arr[0].substring(0, 1);
				if (char >= 'A' && char <= 'Z') {
					result[0] = "K";
					result[1] = codeStr;
				}
			}
		} else if (codeStr.substring(0, 1) == 'Q') {
			var codeEqualQty = 0;
			for (var i = 1; i < codeStr.length; i++) {
				if (codeStr[i] != 0) {
					codeEqualQty = codeStr.substring(i, codeStr.length);
					break;
				}
			}
			result[0] = "Q";
			result[1] = codeEqualQty;
		} else if (codeStr.substring(0, 1) == 'P') {
			var code = codeStr.substring(1, codeStr.length);
			code = code.replace("/", '');
			result[0] = "P";
			result[1] = code;
		} else if (codeStr.substring(0, 1) == 'K') {
			result[0] = "K";
			result[1] = codeStr;
		} else if(codeStr.substring(0, 1) == 'Z'){
			result[0] = "Z";
			var code = codeStr.substring(1, codeStr.length);
			result[1] = code;
			
		}else if(codeStr.substring(0, 4) == 'SZYW'){
			result[0] = "SZYW";
			var code = codeStr.substring(4, codeStr.length);
			result[1] = code;
			
		}
		else if (codeStr.substring(0, 1) == 'T') {
			result[0] = "T";
			result[1] = codeStr.substring(1, codeStr.length);
		} else if (codeStr.includes("/")) {
			var code = codeStr.replace("/", '');
			result[0] = "P";
			result[1] = code;
		} else if (numRe.test(codeStr)) {
			if (codeStr.length <= 4) {
				result[0] = "Q";
			} else if (codeStr.length > 4 && codeStr.length <= 8) {
				result[0] = "P";
			} else {
				result[0] = "C";
			}
			result[1] = codeStr;
		} else {
			result[0] = "O";
			result[1] = '请正确扫描条码';
		}
		return result;
	},

	//判断是不是箱码
	judgeBarCode(codeStr) {
		var numReg = /^[0-9]*$/;
		var numRe = new RegExp(numReg)
		var result = [];
		if (codeStr.includes("-")) {
			var arr = [];
			arr = codeStr.split("-");
			var boxCode = arr[arr.length - 2] + arr[arr.length - 1];
			result[0] = "C";
			result[1] = boxCode;
		} else if (numRe.test(codeStr) && codeStr.length > 10) {
			result[0] = "C";
			result[1] = codeStr;
		} else {
			result[0] = "O";
			result[1] = '请正确扫描箱号';
		}
		return result;
	},
	
	

	judgeAreaCodeOrBoxCode(codeStr) {
		var numReg = /^[0-9]*$/;
		var numRe = new RegExp(numReg)
		var result = [];
		if (codeStr.substring(0, 1) == 'K') {
			result[0] = "K";
			result[1] = boxCode;
		} else if (codeStr.includes("-")) {
			var arr = [];
			arr = codeStr.split("-");
			var boxCode = arr[arr.length - 2] + arr[arr.length - 1];
			result[0] = "C";
			result[1] = boxCode;
		} else if (numRe.test(codeStr) && codeStr.length > 10) {
			result[0] = "C";
			result[1] = codeStr;
		} else {
			result[0] = "O";
			result[1] = '请正确扫描箱号';
		}
		return result;
	},
}